import { Application } from 'egg';
import * as pageFindPlugin from 'mongoose-paginate';

export default (app: Application) => {
  const mongoose = app.mongoose;
  const ObjectId = mongoose.Schema.Types.ObjectId;
  const schema = new mongoose.Schema({
    // 商品ID
    goods: {
      type: ObjectId,
      required: true,
      ref: 'Enjoy',
    },
    // 兑换码
    code: {
      type: String,
      required: true,
      unique: true,
    },
    // 状态
    status: {
      type: String,
      required: true,
    },
    logs: [{
      name: String,
      action: String,
      ctime: String,
    }],
  });
  schema.plugin(pageFindPlugin, {});
  return mongoose.model('Promotion', schema, 'promotion');
};
